package melon.saber.core.event;

import melon.saber.core.AbstractContext;

import com.google.common.eventbus.Subscribe;

/**
 * 订阅者的抽象类，子类可以实现其方法，监听自己感兴趣的事件
 * @author jin
 *
 */
public abstract class Subscriber {
	
	private AbstractContext context;
	
	public Subscriber(AbstractContext context) {
		this.context = context;
		
		context.registerSubscriber(this);
	}

	public AbstractContext getContext() {
		return context;
	}
	
	public <T extends AbstractContext> T getContext(Class<T> clazz) {
		return clazz.cast(context);
	}
	
	@Subscribe abstract public <T extends Event> void listen(T event);

}
